package P1115;/*
 *   exercise
 *   P1115
 *
 *   description:
 *   @data 2025/5/13     下午4:33
 *   @author 凉风
 */

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int max = a[0];
        int current = 0;
        for (int i = 0; i < n; i++) {
            current = Math.max(current + a[i], a[i]);
            max = Math.max(max, current);
        }
        System.out.println(max);
    }
}
